using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class LoaiBenhDAO
    {
       public static bool Insert(LoaiBenhDTO lb)
           {
               bool kq = false;
               try
               {
                   List<SqlParameter> sqlparam = new List<SqlParameter>();
                   sqlparam.Add(new SqlParameter("@MaLoaiBenh", lb.MaLoaiBenh));
                   sqlparam.Add(new SqlParameter("@TenLoaiBenh", lb.TenLoaiBenh));
                   int n = SqlDataAccessHelper.ExecuteNoneQuery("spLoaiBenhInsert",sqlparam);
                   if (n == 1)
                       kq = true;
               }
               catch (Exception ex)
               {
                   throw ex;
               }
               return kq;
           }
       public static bool Delete(LoaiBenhDTO lb)
           {
               bool kq = false;
               try
               {
                   List<SqlParameter> sqlparam = new List<SqlParameter>();
                   sqlparam.Add(new SqlParameter("@MaLoaiBenh", lb.MaLoaiBenh));
                   
                   int n = SqlDataAccessHelper.ExecuteNoneQuery("spLoaiBenhDelete", sqlparam);
                   if (n == 1)
                       kq = true;
               }
               catch (Exception ex)
               {
                   throw ex;
               }
               return kq;
           }
       public static bool Update(LoaiBenhDTO lb)
           {
               bool kq = false;
               try
               {
                   List<SqlParameter> sqlparam = new List<SqlParameter>();
                   sqlparam.Add(new SqlParameter("@MaLoaiBenh", lb.MaLoaiBenh));
                   sqlparam.Add(new SqlParameter("@TenLoaiBenh", lb.TenLoaiBenh));
                   int n = SqlDataAccessHelper.ExecuteNoneQuery("spLoaiBenhUpdate", sqlparam);
                   if (n == 1)
                       kq = true;
               }
               catch (Exception ex)
               {
                   throw ex;
               }
               return kq;
           }
       public static List<LoaiBenhDTO> Select()
           {
               List<LoaiBenhDTO> lst = new List<LoaiBenhDTO>();
               try
               {
                   DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLoaiBenhSelect");
                   foreach (DataRow dr in dt.Rows)
                   {
                       LoaiBenhDTO lb = new LoaiBenhDTO();
                       lb.MaLoaiBenh = int.Parse(dr["MaLoaiBenh"].ToString());
                       lb.TenLoaiBenh = (dr["TenLoaiBenh"].ToString());
                       lst.Add(lb);
                   }
               }
               catch (Exception ex)
               {
                   throw ex;
               }
               return lst;
           }
       public static LoaiBenhDTO SelectByID(int MaLoaiBenh)
           {
               LoaiBenhDTO lb = new LoaiBenhDTO();
               try
               {
                   List<SqlParameter> sqlparam = new List<SqlParameter>();
                   sqlparam.Add(new SqlParameter("@MaLoaiBenh", MaLoaiBenh));
                   DataTable dt = SqlDataAccessHelper.ExecuteQuery("spLoaiBenhSelectByID",sqlparam);
                   DataRow dr = dt.Rows[0];
                   
                   lb.MaLoaiBenh = int.Parse(dr["MaLoaiBenh"].ToString());
                   lb.TenLoaiBenh = (dr["TenLoaiBenh"].ToString());
               }
               catch (Exception ex)
               {
                   throw ex;
               }
               return lb;
           }
    }
}
